import React from 'react';
import { Row, Col } from 'antd';
import { isEqual, isEmpty } from 'lodash';
import {WeaTable, WeaNewScroll, WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
import { intervalMap, formatData } from '../../util/common';
// 新建流程元素
class AddWfCom extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            height: 40
        }
    }

    componentDidUpdate(){
        let _height = $('#element_addwf_scrollId .ant-table-row').height();
        if(_height !=null && !isEqual(_height, this.state.height)){
            this.setState({
                height: _height
            });
        }
    }

    componentDidMount(){
        let _height = $('#element_addwf_scrollId .ant-table-row').height();
        this.setState({
            height: _height
        });
    }
    render() {
        const { data, esetting, contentview, cstyle } = this.props;   
        const { height } =this.state;
        let __height = 5*height;
        if(cstyle.height==undefined){
            __height = 'auto'
        }
        if(contentview && contentview.style && contentview.style.height) {
            __height = cstyle.height;
        }
        const list = data.data;
        const columns = formatData(list[0], esetting);
        if ("1" === esetting.displayLayout) return <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@ua4673`} scrollId="element_addwf_scrollId" height={__height}><WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@as931q`} columns = { columns } showHeader = { false } pagination = { false } dataSource = { list } size = "small" /></WeaNewScroll>
        const evenData = new Array;
        const oddData = new Array;
        intervalMap(list, (item, i) => {
            oddData.push(item);
            if (list[i + 1] !== undefined)
                evenData.push(list[i + 1]);
        }, 2);
        return <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@ttr1eh`}>
                <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@t981e5`} scrollId="element_addwf_scrollId" height={__height}>
                    {
                        isEmpty(evenData) && isEmpty(oddData) ?
                            <div><Row ecId={`${this && this.props && this.props.ecId || ''}_Row@kl0vox`}>
                                <div className="ant-table-placeholder"><span><i className="anticon anticon-frown"></i>{getLabel(83553, '暂无数据')}</span></div>
                            </Row></div>:<div>
                                <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@xlbt4r`} span = { 12 } order = { 1 }>
                                    {!isEmpty(oddData) && <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@y26mv7`} columns = { columns } showHeader = { false } pagination = { false } dataSource = { oddData } size = "small" />}
                                </Col>
                                <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@6wkxdf`} span = { 12 } order = { 2 }>
                                    {!isEmpty(evenData) && <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@2gwxtu`} columns = { columns } showHeader = { false } pagination = { false } dataSource = { evenData } size = "small" />}
                                </Col>
                            </div>
                    }
                    </WeaNewScroll>
            </Row>

    }
}

import { WeaErrorPage, WeaTools } from 'ecCom';
class MyErrorHandler extends React.Component {
    render() {
        const hasErrorMsg = this.props.error && this.props.error !== "";
            return ( < WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@j4axlt`} msg = { hasErrorMsg ? this.props.error : getLabel(385218,"对不起，该页面异常，请联系管理员！") }/>
        );
    }
}

AddWfCom = WeaTools.tryCatch(React, MyErrorHandler, { error: "" })(AddWfCom);
export default AddWfCom;
